/******************************************************************
 * @version      : 1.0
 * @Author       : zhl
 * @Date         : 2022-12-06 14:55:07
 * @LastEditors  : zhl
 * @E-Mail       : zhll168@163.com
 * @Description  : 业务描述
 ******************************************************************/


#ifndef __SECURITY_APDU_H__
#define __SECURITY_APDU_H__

#include <string>
#include <memory>
#include <iostream>

#include "global_data_struct.h"
#include "CConfigManager.h"
#include "GET-Response.h"

typedef enum _SECURITY_APDU_TAG{
    SECURITY_REQUEST    = 16,   //安全请求 [16]
    SECURITY_RESPONSE   = 144   //安全响应 [144] 
}SECURITY_APDU_TAG;

typedef enum _ADU_TYPE{
    ADU_TYPE_PLAINTEXT  = 0,
    ADU_TYPE_CIPHERTEXT = 1,
    ADU_TYPE_ERROR      = 2
}ADU_TYPE;

typedef enum _SECURITY_VERIFY_TYPE{
    SECURITY_VERIFY_TYPE_SID_MAC = 0,   //数据验证码
    SECURITY_VERIFY_TYPE_RN      = 1,   //随机数
    SECURITY_VERIFY_TYPE_RN_MAC  = 2,   //随机数+MAC
    SECURITY_VERIFY_TYPE_SID     = 3    //安全标识
}SECURITY_VERIFY_TYPE;


class Security_APDU{
private:
    /*  */
    static Security_APDU c_security_apdu;

private:
    int parse_security_response(int64_t dev_id, uint8_t *apdu, int len, std::list<Data> &result);
    int get_request_assemble_verify_unit(int verify_unit, uint8_t *apdu, int len);
public:
    Security_APDU();
    ~Security_APDU();

    static Security_APDU *getInstance();
    int parse_apdu(int64_t dev_id, uint8_t *apdu, int len, std::list<Data> &result);

    int get_request_assemble(std::shared_ptr<CConfigManager> cm, TASK_PARAMS *task_params, std::weak_ptr<TERMINAL_DEVICE> dev, uint8_t *apdu, int len);
};


#endif /*__SECURITY_APDU_H__*/